package de.rj.urwalking.util;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;

import de.rj.urwalking.config.Config;

/**
 * Helper class to load {@link Object3D}s from a raw resource.
 * 
 * 
 * @author rjj
 * 
 */

public class ObjHelper {

	private Context context;
	private int[] scene;

	public ObjHelper(Context context, Bundle args) {
		this.context = context;
		scene = args.getIntArray("scene");
	}

	/**
	 * Opens raw resources and builds {@link Object3D}s from .OBJ files.   
	 * @return an {@link ArrayList} of {@link Object3D}s
	 */
	public ArrayList<Object3D> loadObjects() {

		InputStream objStream = context.getResources().openRawResource(scene[0]);
		InputStream mtlStream = context.getResources().openRawResource(scene[1]);

		Object3D[] objectArray = Loader.loadOBJ(objStream, mtlStream, 1);

		if (Config.DEBUG) Log.d(Config.TAG, objectArray.length + " objekte geladen");
		return new ArrayList<Object3D>(Arrays.asList(objectArray));

	}
}
